local ls = require("luasnip")
local s = ls.snippet
local t = ls.text_node
local i = ls.insert_node
local fmt = require("luasnip.extras.fmt").fmt

ls.add_snippets("vim", {
  -- Function
  s("fun", fmt([[
function! {}({})
  {}
endfunction]], {
    i(1, "function_name"),
    i(2, "params"),
    i(3, "\" code"),
  })),

  -- If statement
  s("if", fmt([[
if {}
  {}
endif]], {
    i(1, "condition"),
    i(2, "\" code"),
  })),

  -- For loop
  s("for", fmt([[
for {} in {}
  {}
endfor]], {
    i(1, "item"),
    i(2, "list"),
    i(3, "\" code"),
  })),

  -- While loop
  s("while", fmt([[
while {}
  {}
endwhile]], {
    i(1, "condition"),
    i(2, "\" code"),
  })),

  -- Try catch
  s("try", fmt([[
try
  {}
catch
  {}
endtry]], {
    i(1, "\" code"),
    i(2, "\" error handling"),
  })),

  -- Autocommand
  s("au", fmt([[
augroup {}
  autocmd!
  autocmd {} {} {}
augroup END]], {
    i(1, "group_name"),
    i(2, "event"),
    i(3, "pattern"),
    i(4, "command"),
  })),
})
